package com.zzyl.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.zzyl.dto.NursePlanProjectDto;
import com.zzyl.entity.NursePlanProject;
import com.zzyl.mapper.NursePlanProjectMapper;
import com.zzyl.mapper.NursingProjectMapper;
import com.zzyl.service.NursePlanProjectService;
import com.zzyl.vo.NursePlanProjectVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class NursePlanProjectServiceImpl implements NursePlanProjectService {

    @Autowired
    private NursePlanProjectMapper nursePlanProjectMapper;

    @Override
    public void insert(List<NursePlanProjectDto> projectPlans, Long planId) {
        //将planId设置到dto中
        for (NursePlanProjectDto projectPlan : projectPlans) {
            projectPlan.setPlanId(planId);
        }
        //将dto -> entity
        List<NursePlanProject> list = BeanUtil.copyToList(projectPlans, NursePlanProject.class);
        nursePlanProjectMapper.insertBatch(list);
    }


    @Override
    public void deleteBatch(Long planId) {
        nursePlanProjectMapper.deleteBatch(planId);
    }


    @Override
    public List<NursePlanProjectVo> findById(Long id) {
        List<NursePlanProjectVo> list = nursePlanProjectMapper.findById(id);
        return list;
    }
}
